#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/log"

stats = Hash.new { |h, k| h[k] = [] }
testcase = nil

while (line = $stdin.gets)
  case line
  when /^(.*):\s+(\d+\.\d) MB\/s(.*)$/
    # SSE2 copy : 17668.2 MB/s (0.5%)
    key = $1
    val = $2
    stddev = $3
    key = key.strip.gsub(/[)(]/, '').gsub(/[ -]/, '_')
    stats["RATE." + key + ".MB/s"] = val
    stats["JIT.#{key}.stddev"] = stddev.gsub(/[()% ]/, '') unless stddev.nil?
  when /^block size : single random read \/ dual random read, \[([A-Z_]+)\]$/
    testcase = $1
  when /^\s+(\d+) :/
    # 65536 :    1.3 ns          /     1.9 ns
    size, _, single, _, _, dual = line.split
    # size = size.to_i.to_s(16)
    size = size.to_i >> 10
    stats["LAT.#{testcase}.single_random_read.#{size}k"] = single
    stats["LAT.#{testcase}.dual_random_read.#{size}k"] = dual
  end
end

stats.each do |k, v|
  puts "#{k}: #{v}"
end
